import sys
from .. FTL import ITEMS
from .. FTL import MASTERIES

class Champ:
    def __init__(self):
        self.ID=84
        self.Name="Akali"
        self.InternalName="akali"
        self.Title="The Fist of Shadow"
        self.Icon="Akali.png"
        self.IconData=None
        self.IconSmall="84.jpg"
        self.IconSmallData=None
        self.Level=1
        self.Build={'1':False,'2':False,'3':False,'4':False,'5':False,'6':False}
        self.Masteries={}
        self.BaseAttack_Damage=53
        self.BaseAttack_Damage_delta=3.2
        self.Attack_Damage=0.0
        self.BaseHealth=445
        self.BaseHealth_delta = 85
        self.Health=0
        self.BaseMana=200
        self.BaseMana_delta = 30
        self.Mana=0
        self.BaseMovement_Speed=325
        self.Movement_Speed=0
        self.BaseArmor=16.5
        self.BaseArmor_delta = 3.5
        self.Armor=0
        self.BaseMagic_Resist=30
        self.BaseMagic_Resist_delta = 1.25
        self.Magic_Resist=0
        self.BaseHealth_Regen_per_5_seconds=7.25
        self.BaseHealth_Regen_delta = 0.65
        self.Health_Regen_per_5_seconds=0
        self.BaseMana_Regen_per_5_seconds=50
        self.BaseMana_Regen_delta = 0
        self.Mana_Regen_per_5_seconds=0
        self.BaseAbility_Power=0
        self.Ability_Power=0
        self.BaseSpell_Vamp=0
        self.Spell_Vamp=0
        self.BaseAttack_Speed=0.694
        self.BaseAttack_Speed_delta=3.1
        self.Attack_Speed=0
        self.BaseLife_Steal=0
        self.Life_Steal=0
        self.BaseCooldown_Reduction=0
        self.Cooldown_Reduction=0
        self.BaseCritical_Strike_Chance=0
        self.Critical_Strike_Chance=0
        self.BaseMagic_Penetration_Flat=0
        self.BaseMagic_Penetration_Percentage=0
        self.Magic_Penetration_Flat=0
        self.Magic_Penetration_Percentage=0
        self.BaseArmor_Penetration_Flat=0
        self.BaseArmor_Penetration_Percentage=0
        self.Armor_Penetration_Flat=0
        self.Armor_Penetration_Percentage=0
        self.ManaIsSpecial=True
        # Percentage Bonuses
        self.Movement_Speed_Percentage=0
        self.Attack_Damage_Percentage=0
        self.Mana_Percentage=0
        self.Ability_Power_Percentage=0
        self.Attack_Speed_Percentage=0
        self.Health_Percentage=0
        self.Tenacity=False
        # specials for masteries
        self.SummonersWrath=False
        self.SummonersResolve=False
        self.SummonersInsight=False
        self.ExtraMinionDamage=0
        self.Demolitionist=False
        self.BasePhysical_Damage_Percentage=0
        self.Physical_Damage_Percentage=0
        self.BaseMagical_Damage_Percentage=0
        self.Magical_Damage_Percentage=0
        self.Executioner=False
        self.ToughSkin=0
        self.Indomitable=0
        self.Evasion=0
        self.BladedArmor=False
        self.SiegeCommander=False
        self.Juggernaut=False
        self.Mastermind=False
        # score
        self.CreepScore=0
        self.Kills=0
        self.Deaths=0
        self.Assists=0
        # Skills
        self.Skill_Q_Name="Mark of the Assassin"
        self.Skill_Q_Icon="84-1.jpg"
        self.Skill_Q_MaxStack=False
        self.Skill_Q_Stack=0
        self.Skill_Q_Level=False
        self.Skill_Q_has_Passive=False
        self.Skill_Q_Cooldown=[6,5.5,5,4.5,4]
        self.Skill_Q_Cost=[60,60,60,60,60]
        self.Skill_Q_Priority=[]
        self.Skill_W_Name="Twilight Shroud"
        self.Skill_W_Icon="84-2.jpg"
        self.Skill_W_MaxStack=False
        self.Skill_W_Stack=0
        self.Skill_W_Level=False
        self.Skill_W_has_Passive=False
        self.Skill_W_Cooldown=[20,20,20,20,20]
        self.Skill_W_Cost=[80,75,70,65,60]
        self.Skill_W_Priority=[]
        self.Skill_E_Name="Crescent Slash"
        self.Skill_E_Icon="84-3.jpg"
        self.Skill_E_MaxStack=False
        self.Skill_E_Stack=0
        self.Skill_E_Level=False
        self.Skill_E_has_Passive=False
        self.Skill_E_Cooldown=[7,6,5,4,3]
        self.Skill_E_Cost=[60,55,50,45,40]
        self.Skill_E_Priority=[]
        self.Skill_R_Name="Shadow Dance"
        self.Skill_R_Icon="84-4.jpg"
        self.Skill_R_MaxStack=False
        self.Skill_R_Stack=0
        self.Skill_R_Level=False
        self.Skill_R_has_Passive=False
        self.Skill_R_Cooldown=[2,1.5,1]
        self.Skill_R_Cost=[1,1,1,1,1]
        self.Skill_R_Priority=[]
        self.Skill_P_Name="Twin Disciplines"
        self.Skill_P_Icon="84-5.jpg"
        self.Skill_P_MaxStack=3
        self.Skill_P_Stack=0
        self.Skill_P_Level=False
        self.Skill_P_has_Passive=True
        self.Skill_P_Cooldown=[]
        self.Skill_P_Cost=[]
        self.Skill_P_Priority=[]
        self.LoadIcons()
        self.Custom()
        self.CalcStats()
        self.ResetCurrentStats()

    def ResetStats(self):
        self.Custom()
        self.Attack_Damage=self.BaseAttack_Damage + self.BaseAttack_Damage_delta * self.Level
        self.Health=self.BaseHealth + self.BaseHealth_delta * self.Level
        self.Mana=self.BaseMana + self.BaseMana_delta * self.Level
        self.Health=self.BaseHealth + self.BaseHealth_delta * self.Level
        self.Movement_Speed=self.BaseMovement_Speed
        self.Armor=self.BaseArmor + self.BaseArmor_delta * self.Level
        self.Magic_Resist=self.BaseMagic_Resist + self.BaseMagic_Resist_delta * self.Level
        self.Health_Regen_per_5_seconds=self.BaseHealth_Regen_per_5_seconds + self.BaseHealth_Regen_delta * self.Level
        self.Mana_Regen_per_5_seconds=self.BaseMana_Regen_per_5_seconds + self.BaseMana_Regen_delta * self.Level
        self.Ability_Power=0
        self.Ability_Power_Percentage=0
        self.Spell_Vamp=self.BaseSpell_Vamp
        self.Attack_Speed=self.BaseAttack_Speed * (1.0+((self.BaseAttack_Speed_delta * self.Level)/100))
        self.Attack_Speed_Percentage=0
        self.Life_Steal=self.BaseLife_Steal
        self.Cooldown_Reduction=0
        self.Armor_Penetration_Flat=self.BaseArmor_Penetration_Flat
        self.Armor_Penetration_Percentage=self.BaseArmor_Penetration_Percentage
        self.Critical_Strike_Chance=0
        self.Magic_Penetration_Flat=self.BaseMagic_Penetration_Flat
        self.Magic_Penetration_Percentage=self.BaseMagic_Penetration_Percentage
        self.Physical_Damage_Percentage=self.BasePhysical_Damage_Percentage
        self.Magical_Damage_Percentage=self.BaseMagical_Damage_Percentage

    def LoadIcons(self):
        print "c_poppy: LoadIcons: Called"
        f = open('images/champs/%s' % (self.Icon))
        self.IconData = f.read()
        f.close()

        f = open('images/champs/small/%s' % (self.IconSmall))
        self.IconSmallData = f.read()
        f.close()
        print "c_poppy: LoadIcons: Done"
        
    def ResetCurrentStats(self):
        self.CurrentHealth = self.Health
        self.CurrentMana = self.Mana

    def SetChampLevel(self,level):
        self.Level=int(level)
        self.CalcStats()

    def SetMasteries(self,masteries):
        self.Masteries=masteries
        self.CalcStats()

    def DumpStats(self):
        print "Attack_Damage ", self.Attack_Damage
        print "Health ", self.Health
        print "Mana ", self.Mana
        print "Movement_Speed " ,self.Movement_Speed
        print "Armor ", self.Armor
        print "Magic_Resist ", self.Magic_Resist
        print "Health_Regen ", self.Health_Regen_per_5_seconds
        print "Mana_Regen ", self.Mana_Regen_per_5_seconds
        print "Ability_Power ", self.Ability_Power
        print "Spell_Vamp ", self.Spell_Vamp
        print "Attack_Speed ", self.Attack_Speed
        print "Life_Steal ", self.Life_Steal
        print "Cooldown_Reduction ", self.Cooldown_Reduction
        print "Armor_Penetration_Flat ", self.Armor_Penetration_Flat
        print "Magic_Penetration_Flat ", self.Magic_Penetration_Flat
        print "Armor_Penetration_Percentage ", self.Armor_Penetration_Percentage
        print "Magic_Penetration_Percentage ", self.Magic_Penetration_Percentage
        print "Critical_Strike_Chance ", self.Critical_Strike_Chance
        print "Move_Speed_Percentage ", self.Movement_Speed_Percentage
        print "Attack_Speed_Percentage ", self.Attack_Speed_Percentage
        print "Physical_Damage_Percentage ", self.Physical_Damage_Percentage
        print "Magical_Damage_Percentage ",self.Magical_Damage_Percentage
        print "-------- Skills -------"
        self.Skill_Q(True)
        self.Skill_W(True)
        self.Skill_E(True)
        self.Skill_R(True)

    def CalcStats(self):
        # Reset stats
        self.ResetStats()
        # Add Runes
        #self.ProcessRunes()
        # Add Masteries
        MASTERIES.UpdateStats(self)
        #self.ProcessMasteries()
        # loop through skills passives
        self.Skill_Q(False)
        self.Skill_W(False)
        self.Skill_E(False)
        self.Skill_R(False)

        # loop through items
        for item in self.Build.itervalues():
            if item:
                item.UpdateStats()
        self.Skill_P(False)
        self.CustomCalcStats()
        # Percentage Bonuses
        self.Movement_Speed = self.Movement_Speed * (1+self.Movement_Speed_Percentage/100)
        self.Attack_Damage = self.Attack_Damage * (1+self.Attack_Damage_Percentage/100)
        self.Attack_Speed = self.Attack_Speed * (1+self.Attack_Speed_Percentage/100)
        self.Mana = self.Mana * (1+self.Mana_Percentage/100)
        self.Ability_Power = self.Ability_Power * (1+self.Ability_Power_Percentage/100)
        self.Health = self.Health * (1+self.Health_Percentage/100)
        self.Power_Percentage=0
        self.Health_Percentage=0
        # Limits Check
        if self.Attack_Speed > 2.50:
            self.Attack_Speed=2.50
        if self.Cooldown_Reduction > 40.0:
            self.Cooldown_Reduction=40.0


    def AddItem(self,pos,itemid):
        self.Build[pos]=ITEMS.GetItem(itemid)
        self.Build[pos].parent=self
        self.CalcStats()

    def DelItem(self,pos):
        self.Build[pos]=False
        self.CalcStats()

    def ClearBuild(self):
        for i in range(1,7):
            self.Build[str(i)]=False
        self.CalcStats()

    def Custom(self):
        pass

    def CustomCalcStats(self):
        pass

    def Skill_Q(self,active):
        DAMAGE={}
        DAMAGE['physical']=0
        DAMAGE['magical']=0
        DAMAGE['true']=0
        return DAMAGE

    def Skill_W(self,active):
        DAMAGE={}
        DAMAGE['physical']=0
        DAMAGE['magical']=0
        DAMAGE['true']=0
        return DAMAGE

    def Skill_E(self,active):
        DAMAGE={}
        DAMAGE['physical']=0
        DAMAGE['magical']=0
        DAMAGE['true']=0
        return DAMAGE

    def Skill_R(self,active):
        DAMAGE={}
        DAMAGE['physical']=0
        DAMAGE['magical']=0
        DAMAGE['true']=0
        return DAMAGE

    def Skill_P(self,active):
        DAMAGE={}
        DAMAGE['physical']=0
        DAMAGE['magical']=0
        DAMAGE['true']=0
        if (self.Ability_Power - self.BaseAbility_Power) >= 19.5:
            percent = 7.916
            percent += int((self.Ability_Power - self.BaseAbility_Power - 19.5)/6)
            dmg = (self.Attack_Damage/100) * percent
            self.disciplinesofforcebonusdamage = dmg
        temp = self.BaseAttack_Damage + self.BaseAttack_Damage_delta * self.Level
        if (self.Attack_Damage - temp) >= 9.5:
            percent = 7.916
            percent += int((self.Attack_Damage - temp - 9.5)/6)
            print percent
            spellvamp = (self.Attack_Damage/100) * percent
            self.Spell_Vamp += spellvamp
        return DAMAGE

    def AADamage(self):
        DAMAGE={}
        DAMAGE['physical']=self.Attack_Damage
        DAMAGE['physical'] *= (1 + self.Physical_Damage_Percentage/100)
        DAMAGE['magical']=self.disciplinesofforcebonusdamage
        DAMAGE['true']=0
        return DAMAGE
